<!-- 车型管理 -->
<template>
  <div class="dashboard-container operational-range customer-list-box">
    <div class="app-container">
      <!-- 搜索 -->
      <el-card
        class="search-card-box"
        shadow="never"
      >
        <el-form
          ref="carSearchFormData"
          :model="carSearchFormData"
          label-width="95px"
        >
          <el-row :gutter="60">
            <el-col :span="8">
              <el-form-item
                label="车型编号:"
                style="margin-bottom: 0px"
              >
                <el-input
                  v-model="carSearchFormData.id"
                  clearable
                  placeholder="请输入车型编号"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="应载重量:"
                style="margin-bottom: 0px"
              >
                <el-select
                  v-model="carSearchFormData.allowableLoad"
                  placeholder="请选择应载重量"
                >
                  <el-option
                    v-for="item in optionsWeight"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="应载体积:"
                style="margin-bottom: 0px"
                label-width="110px"
              >
                <el-select
                  v-model="carSearchFormData.allowableVolume"
                  placeholder="请选择应载体积"
                >
                  <el-option
                    v-for="item in optionsVolume"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                prop="username"
                label="车辆类型:"
                style="margin-top: 20px; margin-bottom: 0px"
              >
                <el-input
                  v-model="carSearchFormData.name"
                  clearable
                  placeholder="请输入车辆类型"
                />
              </el-form-item>
            </el-col>
            <el-col
              :span="8"
              style="margin-top: 20px"
            >
              <el-button
                type="warning"
                @click="handleFilter"
              >搜索</el-button>
              <el-button
                plain
                class="reset-btn"
                @click="resetForm"
              >重置</el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <div
        v-loading="listLoading"
        element-loading-text="加载中"
        style="margin-top: 20px"
      >
        <el-card
          class="table-card-box"
          shadow="never"
        >
          <el-button
            class="add-btn"
            type="warning"
            @click="openDialog"
          >新增车型</el-button>
          <el-table
            :key="tableKey"
            ref="multipleTable"
            :data="dataList"
            style="width: 100%"
            stripe
            :header-cell-style="{ background: 'rgba(250,252,255,1)' }"
          >
            <el-table-column
              align="left"
              type="index"
              label="序号"
              width="100px"
              :index="carindex"
            >
            </el-table-column>
            <el-table-column
              align="left"
              label="车辆编号"
              min-width="170px"
              prop="id"
            >
              <!-- <template slot-scope="scope">
                <span>{{ scope.row.account }}</span>
              </template> -->
            </el-table-column>
            <el-table-column
              align="left"
              label="车辆类型"
              prop="name"
              min-width="150px"
            >
              <!-- <template slot-scope="scope">
                <span>{{ scope.row.name }}</span>
              </template> -->
            </el-table-column>
            <el-table-column
              align="left"
              label="车辆数量"
              min-width="120px"
              prop="num"
            >

            </el-table-column>
            <el-table-column
              align="left"
              label="应载重量(吨)"
              min-width="120px"
              prop="allowableLoad"
            >
            </el-table-column>
            <el-table-column
              align="center"
              label="应载重量(立方米)"
              min-width="110px"
              prop="allowableVolume"
            >
            </el-table-column>
            <el-table-column
              align="center"
              label="长(米)"
              min-width="70px"
              prop="measureLong"
            >
            </el-table-column>
            <el-table-column
              align="center"
              label="宽(米)"
              prop="measureWidth"
              min-width="70px"
            >
            </el-table-column>
            <el-table-column
              align="center"
              label="高(米)"
              prop="measureHigh"
              min-width="70px"
            >
            </el-table-column>
            <!-- 操作按钮 -->
            <el-table-column
              align="center"
              label="操作"
              width="240px"
              class-name="small-padding fixed-width"
              fixed="right"
            >
              <template #default="{row}">
                <el-button
                  size="mini"
                  @click="editCarBtn(row)"
                >编辑</el-button>
                <el-button
                  size="mini"
                  type="danger"
                  @click="delCarBtn(row.id)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- end -->
          <!-- 分页 -->
          <div class="pagination">
            <div
              v-show="dataList && dataList.length > 0"
              class="pages"
            >
              <el-pagination
                :total="total"
                :page-size="carSearchFormData.pageSize"
                :page-sizes="[10, 20, 30]"
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              />
            </div>
          </div>
        </el-card>
      </div>
      <div>
        <car-models-add
          :dialog-form-visible="dialogFormVisible"
          :car-type-list="carTypeList"
          :car-models-list="carModelsList"
          @closeFormVisible="closeFormVisible"
        />
      </div>
    </div>
  </div>
</template>
<script>
import { list, del } from '@/api/transit'
import carModelsAdd from './components/car-models-add.vue'
export default {
  components: {
    carModelsAdd
  },
  data () {
    return {
      tableKey: 0,
      dataList: [], // 初始化数据
      searchkey: false,
      total: null, // 条数
      listLoading: false,
      alertText: '',
      carSearchFormData: {
        page: 1,
        pageSize: 10,
        allowableLoad: '', // 车型载重
        allowableVolume: '', // 车型体积
        id: '', // 车型id
        name: '' // 车辆类型名称
      },
      optionsWeight: [{
        value: 'RANGE_LEVEL_1',
        name: '<1.8（吨）'
      },
      {
        value: 'RANGE_LEVEL_2',
        name: '1.8-6（吨）'
      },
      {
        value: 'RANGE_LEVEL_3',
        name: '6-14（吨）'
      },
      {
        value: 'RANGE_LEVEL_4',
        name: '14-30（吨）'
      },
      {
        value: 'RANGE_LEVEL_5',
        name: '30-50（吨）'
      },
      {
        value: 'RANGE_LEVEL_6',
        name: '50-100（吨）'
      },
      {
        value: 'RANGE_LEVEL_7',
        name: '100>（吨）'
      }],
      optionsVolume: [
        {
          value: 'RANGE_LEVEL_1',
          name: '<3（m³）'
        },
        {
          value: 'RANGE_LEVEL_2',
          name: '3-5（m³）'
        },
        {
          value: 'RANGE_LEVEL_3',
          name: '5-10（m³）'
        },
        {
          value: 'RANGE_LEVEL_4',
          name: '10-15（m³）'
        },
        {
          value: 'RANGE_LEVEL_5',
          name: '15-30（m³）'
        },
        {
          value: 'RANGE_LEVEL_6',
          name: '30-50（m³）'
        },
        {
          value: 'RANGE_LEVEL_7',
          name: '50-80（m³）'
        },
        {
          value: 'RANGE_LEVEL_8',
          name: '80-150（m³）'
        },
        {
          value: 'RANGE_LEVEL_9',
          name: '150>（m³）'
        }
      ],
      dialogFormVisible: false, // 组件弹框
      carModelsList: {}
    }
  },
  mounted () {
    this.carTypeList()
  },
  methods: {
    // 初始化
    async carTypeList () {
      this.listLoading = true
      const { data } = await list(this.carSearchFormData)
      this.dataList = data.items
      this.listLoading = false
      this.total = +data.counts
    },
    // 删除按钮
    delCarBtn(id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        await del(id)
        this.carTypeList()
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {})
    },
    // 序号
    carindex(index) {
      const { page, pageSize } = this.carSearchFormData
      return index + 1 + (page - 1) * pageSize
    },
    // 编辑按钮
    editCarBtn(data) {
      console.log(data)
      this.carModelsList = data
      this.dialogFormVisible = true
    },
    // 打开弹框
    openDialog() {
      this.dialogFormVisible = true
    },
    // 关闭弹框
    closeFormVisible(val) {
      this.dialogFormVisible = val
      this.carModelsList = {
        allowableLoad: '',
        allowableVolume: '',
        goodsTypes: '',
        id: '',
        measureHigh: '',
        measureLong: '',
        measureWidth: '',
        name: '',
        num: null
      }
    },
    // 搜索
    handleFilter() {
      this.carTypeList()
    },
    // 重置
    resetForm() {
      this.carSearchFormData = {
        page: 1,
        pageSize: 5,
        allowableLoad: '',
        allowableVolume: '',
        id: '',
        name: ''
      }
      this.carTypeList()
    },
    // 每页数量
    handleCurrentChange(val) {
      this.carSearchFormData.page = val
      this.carTypeList()
    },
    // 每页条数
    handleSizeChange(val) {
      this.carSearchFormData.pageSize = val
      this.carTypeList()
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.operational-range {
  .el-card {
    overflow: initial;
  }
}
.el-card__body {
  margin-top: 20px;
  padding: 20px;
}
.add-btn {
  margin-bottom: 20px;
}
.alert {
  margin: 10px 0px;
}
.pagination {
  margin-top: 40px;
  padding-bottom: 0px;
}
.el-select {
  width: 100%;
}

.car-models /deep/ .el-table td,
.el-table th {
  padding: 12px 0;
  min-width: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: left;
  overflow: hidden;
}
.car-models {
  /deep/ .el-dialog__title {
    width: 73px;
    height: 25px;
    font-size: 18px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: left;
    color: #20232a;
    line-height: 25px;
    letter-spacing: 0px;
  }
  /deep/ .el-dialog__body {
    text-align: center;
    padding: 40px 60px 0 30px;
  }
  .warn-img {
    width: 40px;
  }
  p {
    height: 24px;
    font-size: 16px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    color: #818693;
    line-height: 24px;
  }
}
</style>
